﻿using System.Security.Cryptography;
using System.Text;

namespace FrameWork
{
   public static class Md5Help
   {
       public static string Encrypt(string source, string key = null)
       {
            if (!string.IsNullOrWhiteSpace(key)) source += "&key=" + key;

            var md5Hasher = MD5.Create();
            var data = md5Hasher.ComputeHash(Encoding.UTF8.GetBytes(source));
            var sBuilder = new StringBuilder();
            foreach (var itm in data)
            {
                sBuilder.Append(itm.ToString("x2"));
            }
            return sBuilder.ToString();
        }
    }
}
